package com.kingdee.pda.ui.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;

import com.kingdee.pda.R;

/**
 * 对TextView的文本颜色进行选择改变
 * Created by zhanlg
 * DATE 2018/9/26
 * TIME 16:56
 */
public class SelectorTextView extends AppCompatTextView {

    private Context mContext;
    private int mSelectedTextColor;
    private int mUnselectedTextColor;

    public SelectorTextView(Context context) {
        this(context, null);
    }

    public SelectorTextView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SelectorTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        mUnselectedTextColor = getCurrentTextColor();
        final TypedArray attributes = mContext.getTheme().obtainStyledAttributes(attrs, R.styleable.SelectorTextView, defStyleAttr, 0);
        mSelectedTextColor = attributes.getColor(R.styleable.SelectorTextView_selectedTextColor, Color.BLACK);
    }

    @Override
    public boolean isSelected() {
        return super.isSelected();
    }

    @Override
    public void setSelected(boolean selected) {
        setTextColor(selected ? mSelectedTextColor : mUnselectedTextColor);
        super.setSelected(selected);
    }

}
